package com.hmall.es.controller;

import com.hmall.common.dto.PageResult;
import com.hmall.es.pojo.RequestParams;
import com.hmall.es.service.ISearchService;
import org.springframework.boot.test.autoconfigure.orm.jpa.AutoConfigureTestEntityManager;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.List;
import java.util.Map;

/**
 * 搜索的业务方法
 */
@RestController
@RequestMapping("/search")
public class SearchController {

    @Resource
    private ISearchService searchService;
    /**
     * 自动补全功能
     * @param key
     * @return
     */
    @GetMapping("/suggestion")
    public List<String> suggestionList(@RequestParam("key") String key) throws IOException {
        return searchService.suggestionList(key);
    }

    /**
     * 过滤筛选品牌和分类结果展示
     * @return
     */
    @PostMapping("/filters")
    public Map<String,List<String>> filters(@RequestBody RequestParams params) throws IOException {
        return searchService.filters(params);
    }

    /**
     * 基本搜索查询
     * @param params
     * @return
     */
    @PostMapping("/list")
    public PageResult list(@RequestBody RequestParams params) throws IOException {
        return searchService.list(params);
    }


    /**
     * 校验是否能够从请求头中获取参数
     */
    @GetMapping
    public void test(HttpServletRequest request){
        String header = request.getHeader("authorization");
        System.out.println(header);
    }
}
